import { Component, OnInit, ViewChild } from '@angular/core';
import {MatPaginator} from '@angular/material/paginator';
import {MatTableDataSource} from '@angular/material/table';

const data = [
  {
    title:"泰州－盐城－淮安－徐州线",
    link:"tz",
  },
  {
    title:"南京－镇江－句容－常熟线",
    link:"nj",
  },
  {
    title:"韶山－宁乡－平江线",
    link:"ss",
  },
  {
    title:"哈尔滨－阿城－尚志－海林－牡丹江线",
    link:"heb",
  },
  {
    title:"成都－雅安－石棉－泸定－康定线",
    link:"cd",
  },
  {
    title:"赣州－瑞金－于都－会昌－长汀－上杭－古田线",
    link:"zz",
  },
  {
    title:"上海－嘉兴－平阳线",
    link:"sh",
  },
  {
    title:"贵阳－凯里－镇远－黎平－通道－桂林线",
    link:"gz",
  },
  {
    title:"黄山－绩溪－旌德－泾县－宣城－芜湖线",
    link:"hs",
  },
]

@Component({
  selector: 'app-travel',
  templateUrl: './travel.component.html',
  styleUrls: ['./travel.component.less']
})
export class TravelComponent implements OnInit {
  displayedColumns: string[] = ['title'];
  dataSource:MatTableDataSource<any>;

  @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;

  constructor() { 
    this.dataSource = new MatTableDataSource(data);
    console.log(this.dataSource,data)
  }

  ngOnInit() {
    this.dataSource.paginator = this.paginator;
  }

  applyFilter(filterValue: string) {
    this.dataSource.filter = filterValue.trim().toLowerCase();


    console.log(this.dataSource)
    if (this.dataSource.paginator) {
      this.dataSource.paginator.firstPage();
    }
  }

}
